home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freaks Macintosh Archive
/
Freaks Macintosh Archive.bin
/
Freaks Macintosh Archives
/
Aol
/
aol-Hells
/
InOLv2.2.sit
/
InOLv2.2
/
No Dice ƒ
/
No Dice INIT.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-29
|
6KB
|
322 lines
// -------------------------------------------------------------------------
// -- No Dice 1.0.0
// -- by Andrew Welch
// -- Copyright 1995 by Ambrosia Software, Inc.
// -- Ignore those annoying dice rolls that people seem to love using in
// -- chat rooms.
// -------------------------------------------------------------------------
// -- #include files for No Dice INIT
#include "Assembler.h"
#include "A4Stuff.h"
// -------------------------------------------------------------------------
// -- #defines for No Dice INIT
#define AOL_CREATOR 'AOqc'
#define INIT_RES_ID 128
#define JMP 0x4EF9
#define TESTYLEINSERT_SELECTOR 7
#define ONLINE_HOST_LEN 10
#define ROOM_NAME_LEN 17
#define RETURN_CHAR 0x0D
#define BLANK_LINE 0x0D202020
// -------------------------------------------------------------------------
// -- function prototypes for No Dice INIT
asm void main(void);
Boolean IsAOLRunning(void);
Boolean TrapAvailable(short theTrap);
Boolean InAOLChatRoom(TEHandle theTE);
Boolean CensorInsertion(long textLenth, char *theText);
// -------------------------------------------------------------------------
// -- Globals used in No Dice
static char gOnlineHostName[10] = {"OnlineHost"};
static char gRoomName[17] = {"People Connection"};
// -------------------------------------------------------------------------
// -- No Dice INIT main
asm void main(void)
{
// -- Detach this code resource
clr.l -(SP)
move.l #'INIT', -(SP)
move.w #INIT_RES_ID, -(SP)
_Get1Resource
tst.l (SP)
beq @skipOut
_DetachResource
// -- Now patch _TEDispatch
move.l #_TEDispatch, D0
_GetTrapAddress + newToolTrap
lea @origTEDispatch,A1
move.w #JMP, (A1)+
move.l A0, (A1)
move #_TEDispatch,D0
lea @TEDispatchPatch, A0
_SetTrapAddress + newToolTrap
rts
// -- There was some problem loading -- simply exit
@skipOut:
rts
// -------------------------------------------------------------------------
// -- Our patch to TEDispatch -- look for calls to TEStyleInsert
@TEDispatchPatch:
// -- See if TEStyleInsert is being called
cmp.w #TESTYLEINSERT_SELECTOR, 4(SP)
bne @origTEDispatch
// -- Now make sure that AOL is the frontmost application
jsr IsAOLRunning
tst.b D0
beq @origTEDispatch
// -- See if we are in a chat room
move.l 6(SP), -(SP)
jsr InAOLChatRoom
add.l #4, SP
tst.b D0
beq @origTEDispatch
// -- See if we should automatically ignore this insertion
lea @autoIgnore, A0
tst.w (A0)
beq @noAutoIgnore
sub.w #1, (A0)
lea @blankIgnore, A0
move.w #1, (A0)
bra @censorIt
// -- See if we should ignore the next line if it is blank
@noAutoIgnore:
lea @blankIgnore, A0
tst.w (A0)
beq @noBlankIgnore
sub.w #1, (A0)
// -- Verify that this is indeed a blank line
move.l 18(SP), A0
cmp.l #BLANK_LINE, (A0)
bne @noBlankIgnore
// -- Ignore this blank line and the next one too
lea @autoIgnore, A0
move.w #1, (A0)
bra @censorIt
// -- Finally, see if we should censor this insertion
@noBlankIgnore:
move.l 18(SP), -(SP)
move.l 18(SP), -(SP)
jsr CensorInsertion
add.l #8, SP
tst.b D0
beq @origTEDispatch
// -- Make sure the next insertion is ignored as well
lea @autoIgnore, A0
move.w #1, (A0)
// -- We _should_ censor this insertion -- simple set the length to 0
@censorIt:
clr.l 14(SP)
@origTEDispatch:
nop
nop
nop
@autoIgnore: dc.w 0
@blankIgnore: dc.w 0
} // -- main
// -------------------------------------------------------------------------
// -- Use the process manager to find out if AOL is the current process
Boolean IsAOLRunning(void)
{
OSErr err;
Boolean result = false;
// -- Make sure the process manager is up and running first
if (TrapAvailable(_OSDispatch))
{
ProcessSerialNumber theProcess;
FSSpec processSpec;
char processName[32];
// -- Get the current process's serial number
err = GetCurrentProcess(&theProcess);
if (err == noErr)
{
ProcessInfoRec processInfo;
// -- Setup the ProcessInfoRec
processInfo.processInfoLength = sizeof(processInfo);
processInfo.processName = (StringPtr)&processName;
processInfo.processAppSpec = &processSpec;
// -- Get information on the current process
err = GetProcessInformation(&theProcess, &processInfo);
if (err == noErr)
{
// -- See if this process has the same creator as AOL does
if (processInfo.processSignature == AOL_CREATOR)
result = true;
}
}
}
return result;
} // -- DrawMenuBarPatch
// -------------------------------------------------------------------------
// -- Is this TERec in an AOL Chat Room window?
Boolean InAOLChatRoom(TEHandle theTE)
{
Boolean result = false;
long oldA4;
oldA4 = SetCurrentA4();
if (theTE != nil)
{
WindowPtr theWindow;
Str255 theTitle;
short index;
// -- Get the window's title that the TERec is drawn in
theWindow = (WindowPtr)(**theTE).inPort;
GetWTitle(theWindow, (StringPtr)&theTitle);
// -- Now see if it matches what we're looking for
for (index = 0; index < ROOM_NAME_LEN; index++)
{
if (theTitle[index + 1] != gRoomName[index])
goto NoMatch;
}
result = true;
NoMatch:
index = 0;
}
SetA4(oldA4);
return result;
} // -- InAOLChatRoom
// -------------------------------------------------------------------------
// -- Should this text insertion be censored?
Boolean CensorInsertion(long textLenth, char *theText)
{
Boolean result = false;
long oldA4;
oldA4 = SetCurrentA4();
if (textLenth > 10)
{
short index;
// -- Ignore any return characters
while ((*theText) == RETURN_CHAR)
theText++;
// -- Loop through and see if this is an online host message
for (index = 0; index < ONLINE_HOST_LEN; index++)
{
if ((*theText) != gOnlineHostName[index])
goto NoMatch;
theText++;
}
result = true;
NoMatch:
index = 0;
}
SetA4(oldA4);
return result;
} // -- CensorInsertion
// -------------------------------------------------------------------------
// -- Is the theTrap available?
Boolean TrapAvailable(short theTrap)
{
Boolean result = true;
if (GetTrapAddress(_Unimplemented) == GetTrapAddress(theTrap))
result = false;
return result;
} // -- TrapAvailable